package com.xbongbong.saas.help;

import com.xbongbong.paas.log.MongoLogHelp;
import com.xbongbong.paas.pojo.AttrValuePojo;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.parent.util.LogUtil;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.saas.enums.OperateModuleTypeEnum;
import com.xbongbong.saas.model.LabelModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 业务日志支持类
 *
 * @author youli.chen
 * @version v1.0
 * @date 2021/1/15 09:43
 * @since v1.0
 */
@Component
@Slf4j
public class LogHandleHelp {
    @Resource
    private LabelModel labelModel;
    @Resource
    private MongoLogHelp mongoLogHelp;


    public void handleRefTypeLabelLog(AddLabelDTO addLabelDTO, List<String> names, OperateModuleTypeEnum operateModuleTypeEnum, String refName, Boolean addOrDelete) throws XbbException {
        /*// 批量打标签/移除标签日志
        OperateTypeEnum operateTypeEnum;
        if(addOrDelete){
            operateTypeEnum = OperateTypeEnum.ADD_LABEL;
        } else {
            operateTypeEnum = OperateTypeEnum.REMOVE_LABEL;
        }
        String corpid = addLabelDTO.getCorpid();
        String userId = addLabelDTO.getUserId();
        String userName = addLabelDTO.getLoginUserName();

        List<Long> labelIds = addLabelDTO.getLabelIds();
        List<String> labelList = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        if(CollectionUtils.isNotEmpty(labelIds)){
            List<LabelEntity> labelEntityList = labelModel.getByLabelIds(labelIds, corpid);
            labelEntityList.forEach(labelEntity -> labelList.add(labelEntity.getName()));
            String labelName = StringUtils.join(labelList, "，");
            String memo;
            if(labelList.size() > 1){
                if(addOrDelete){
                    memo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.LOG_MEMO_USER_BATCH_UPDATE_ADD_LABEL_FORM_DETAIL), userName, refName, names, labelList.size());
                } else {
                    memo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.LOG_MEMO_USER_BATCH_UPDATE_REMOVE_LABEL_FORM_DETAIL), userName, refName, names, labelList.size());
                }
                List<InfoArrPojo> infoArrPojoList = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                InfoArrPojo infoArrPojo = new InfoArrPojo();
                infoArrPojo.setTitle(FieldTypeEnum.LABEL.getDescription());
                infoArrPojo.setContent(labelName);
                infoArrPojoList.add(infoArrPojo);
                mongoLogHelp.buildLog4InfoArr(infoArrPojoList, corpid, userId, userName, operateModuleTypeEnum, operateTypeEnum, "", "", memo, addLabelDTO.getHttpHeader());
            } else if (Objects.equals(labelList.size(), 1)){
                if(addOrDelete){
                    memo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.LOG_MEMO_USER_UPDATE_ADD_LABEL_WORK), userName, refName, names, labelName);
                } else {
                    memo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.LOG_MEMO_USER_UPDATE_REMOVE_LABEL_WORK), userName, refName, names, labelName);
                }
                mongoLogHelp.buildLog(corpid, userId, userName, operateModuleTypeEnum, operateTypeEnum, labelList.get(0), labelName, memo, addLabelDTO.getHttpHeader());
            }

            // if (!Objects.equals(DistributorMarkEnum.DISTRIBUTOR.getCode(), addLabelDTO.getDistributorMark())) {
            //     DynamicStrategy dynamicStrategy = dynamicStrategyFactory.getDynamicStrategyByBusinessType(addLabelDTO.getBusinessType());
            //     dynamicStrategy.label(DynamicLabelDTO.initDynamicLabelDTO(addLabelDTO, addOrDelete));
            // }

        }*/
    }
    /**
     * 获取改变的日志信息
     * @param logFieldEditedList
     * @return
     * @throws XbbException
     */
    public String getChangedLogItemsStr(List<AttrValuePojo> logFieldEditedList) throws XbbException {
        return LogUtil.getChangedLogItemsStr(logFieldEditedList);
    }
}
